package com.gy.paidao.setting;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.TextView;

import com.gy.paidao.BaseActivity;
import com.example.mapdemo.R;
import com.gy.paidao.bean.BaseBean;
import com.gy.paidao.util.AnimUtil;
import com.gy.paidao.util.SPHelper;
import com.gy.paidao.util.Urls;
import com.jky.struct2.http.core.AjaxParams;

/**
 * 作者：gy on 16/4/28
 * 说明：重置密码
 */
public class ReSetPwdActivity extends BaseActivity {

    private EditText etOld, etOne, etSecond;
    private TextView tvReset;
    private String strOld, strOne, strSecond;
    private String userLoginID;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_pwd);
        setViews();
    }

    @Override
    protected void initVariable() {
        userLoginID = SPHelper.getInstance(this).getStringData("userLoginID", null);
    }

    @Override
    protected void setTitleViews() {

    }

    @Override
    protected void setViews() {
        etOld = (EditText) findViewById(R.id.activity_reset_et_password_old);
        etOne = (EditText) findViewById(R.id.activity_reset_et_password_one);
        etSecond = (EditText) findViewById(R.id.activity_reset_et_password_second);
        tvReset = (TextView) findViewById(R.id.activity_reset_tv_reset);

        tvReset.setOnClickListener(this);
    }

    @Override
    protected void doClickAction(int viewId) {
        super.doClickAction(viewId);
        switch (viewId) {
            case R.id.activity_reset_tv_reset:
                strOld = etOld.getText().toString().trim();
                strOne = etOld.getText().toString().trim();
                strSecond = etOld.getText().toString().trim();
                if (TextUtils.isEmpty(strOld) || TextUtils.isEmpty(strOne)
                        || TextUtils.isEmpty(strSecond)) {
                    showToast("请完善输入信息");
                } else if (!strOne.equals(strSecond)) {
                    showToast("两次密码输入不一致");
                } else {
                    dorequestReset();
                }
                break;
        }
    }

    private void dorequestReset() {
        params = new AjaxParams();
        params.put("oldPassword",strOld+ "");
        params.put("newPassword",strOld+ "");
        httpRequest.addHeader("Cookie", "userLoginID=" + userLoginID);
        httpRequest.post(Urls.url_reset,params,callBack,0);
    }

    @Override
    protected void handlerBean(int requestCode, BaseBean baseBean) {
        super.handlerBean(requestCode, baseBean);
        dismissLoading();
        if (baseBean.success) {
            showToast("修改成功");
            finish();
            AnimUtil.pushRightInAndOut(this);
        } else {
            if (!TextUtils.isEmpty(baseBean.errMsg)) {
                showToast(baseBean.errMsg);
            }
        }
    }
}
